<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-body layui-anim layui-anim-up">
        <form class="layui-form" action="addPurchase" id="form">
          <div class="layui-form-item">
               <label for="purchaseTime" class="layui-form-label">
                  <span class="x-red">*</span>采购时间
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="purchaseTime" name="purchaselist.purchaseTime" required="" lay-verify=""
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="payType" class="layui-form-label">
                  <span class="x-red">*</span>昵称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="payType" name="purchaselist.payType" required="" lay-verify="" 
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="invoiceAmount" class="layui-form-label">
                  <span class="x-red">*</span>发票金额
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="invoiceAmount" name="purchaselist.invoiceAmount" required="" lay-verify=""
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="invoiceNumber" class="layui-form-label">
                  <span class="x-red">*</span>发票编号
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="invoiceNumber" name="purchaselist.invoiceNumber" required="" lay-verify=""
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="realpay" class="layui-form-label">
                  <span class="x-red">*</span>实际金额
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="realpay" name="purchaselist.realpay" required="" lay-verify=""
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="stockNumber" class="layui-form-label">
                  <span class="x-red">*</span>进货单号
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="stockNumber" name="purchaselist.stockNumber" required="" lay-verify=""
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="supplierName" class="layui-form-label">
                  <span class="x-red">*</span>供应商名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="supplierName" name="purchaselist.supplierName" required="" lay-verify=""
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="purchasePerson" class="layui-form-label">
                  <span class="x-red">*</span>采购人员
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="purchasePerson" name="purchaselist.purchasePerson" required="" lay-verify=""
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="invoicePhoto" class="layui-form-label">
                  <span class="x-red">*</span>发票图片
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="invoicePhoto" name="purchaselist.invoicePhoto" required="" lay-verify=""
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="contractPhoto" class="layui-form-label">
                  <span class="x-red">*</span>合同图片
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="contractPhoto" name="purchaselist.contractPhoto" required="" lay-verify=""
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="freight" class="layui-form-label">
                  <span class="x-red">*</span>运费
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="freight" name="purchaselist.freight" required="" lay-verify=""
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="addPurchase" lay-submit="">增加</button>
          </div>
      </form>
    </div>
    <script>
     layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#purchaseTime' //指定元素
        });

      });
    
    
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 5){
                return '昵称至少得5个字符啊';
              }
            }
            ,pass: [/(.+){1,12}$/, '金额必须1到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
          });

          //监听提交
          form.on('submit(addPurchase)', function(data){
        	  console.log(data);
        	  var index = parent.layer.getFrameIndex(window.name);
        	  $.ajax({
      			url:"addPurchase",
      			type:"post",
      			data:$("#form").serialize(),
      			success:function(data){
      				var backdata=JSON.parse(data);
      				if(backdata.msg=="ok"){
      				  console.log("OK");
      				  layer.alert("增加成功", {icon: 6},function () {
      					    
      		                parent.layer.close(index);
      		          });	
      				}else{
      					console.log("ERROR");
      				  layer.alert("增加失败", {icon: 6},function () {
      		                parent.layer.close(index);
      		          });
      				}
      			} 
      		  });
        	  
        	  
        	  
            
            return false;
          });
          
          
        });
    </script>

  </body>

</html>